//
//  TransferFooterCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/31.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit

class TransferFooterCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource {
    var modelList: [TransferModel] = []{
        didSet{
            if self.modelList[0].type == "物品"{
                self.name.text = "同类宝贝"
            }else{
                self.name.text = "附近吉铺"
            }
            self.tableView.reloadData()
            
        }
    }
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var name: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.scrollEnabled = false
        let cellNib = UINib(nibName: "TransFooterCell2", bundle: nil)
        self.tableView.registerNib(cellNib, forCellReuseIdentifier: "TransFooterCell2")

        publicMethod.hiddleExtendCellForTableView(self.tableView)
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if modelList.count == 0{
            return 0
        }else{
            return (modelList.count)
        }
        
    }
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        return 100
        
        
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCellWithIdentifier("TransFooterCell2", forIndexPath: indexPath) as! TransFooterCell2
        
        cell.icon.sd_setImageWithURL(NSURL(string: self.modelList[indexPath.row].imgsrc), placeholderImage: UIImage(named: "placeholder"))
        cell.title.text = self.modelList[indexPath.row].name
        cell.address.text = self.modelList[indexPath.row].address
        cell.price.text = self.modelList[indexPath.row].price
        cell.time.text = publicMethod.computationTimeDifference(self.modelList[indexPath.row].ptime)
        cell.type.text = self.modelList[indexPath.row].type

        return cell
    }
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        let model = self.modelList[indexPath.row]
        
        if model.type == "整店" {
            
            let dic = ["id":model.id, "type":model.type]
            NSNotificationCenter.defaultCenter().postNotificationName(transShop_noti, object: dic)
            
        }else{
            
            let dic = ["id":model.id, "type":model.type]
            NSNotificationCenter.defaultCenter().postNotificationName(transGoods_noti, object: dic)
        }

        
        
    }
    
}
